﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WyUnity.Data.DataAccess;
using WyUnity.Data.Query;
using WyUnity.Data.TableMapper;

namespace DAL_13_0.Entities
{
    [Map("t_Item")]
    [Serializable]
    public class Item : TableBase<Item>
    {
        [Map("FNumber")]
        public string Number { get; set; }
        [Map("FName")]
        public string Name { get; set; }
        [Map("FItemID")]
        public int ID { get; set; }
        [Map("FItemClassID")]
        public int ClassID { get; set; }
        [Map("FDeleted")]
        public bool IsDeleted { get; set; }
        [Map("FDetail")]
        public bool IsDetail { get; set; }

        public static FieldBase pNumber = new Field<Item>(p => p.Number);
        public static FieldBase pName = new Field<Item>(p => p.Name);
        public static FieldBase pID = new Field<Item>(p => p.ID);
        public static FieldBase pClassID = new Field<Item>(p => p.ClassID);
        public static FieldBase pIsDeleted = new Field<Item>(p => p.IsDeleted);
        public static FieldBase pIsDetail = new Field<Item>(p => p.IsDetail);

        public static Item Get(DbSession session, int itemid)
        {
            return session.QuerySingle<Item>(pID == itemid);
        }

        public static Item Get(DbSession session, string number, int classid)
        {
            return session.QuerySingle<Item>(pClassID == classid & pNumber == number);
        }

        public static int GetID(DbSession session, string number, int classid)
        {
            return session.QueryField<Item, int>(pID, pClassID == classid & pNumber == number);
        }
    }

}